<?php $this->renderPartial('/admin/menu/reports');?>
<h4><?php echo Yii::t('helpdesk','Logs'); ?></h4>
<?php 
foreach(Yii::app()->user->getFlashes() as $key => $message){
	echo '<div class="'.$key.'"><p>'.$message."</p></div>\n";
}
?>

<form method="get" name="frmFilter" id="frmFilter">
    <fieldset>
        <legend style="cursor:pointer;"><span style="font-size:12px;"><i class="fa fa-minus-square-o" id="filterIcon"></i></span> <?php echo Yii::t('helpdesk','Filter'); ?></legend>        
        <div class="form-group">	
            <label for="action" class="col-md-1"><?php echo Yii::t('helpdesk','Actions'); ?>:</label>	
            <select onchange="$('#frmFilter').submit();" name="action" id="action" class="form-inline">
                <option value="">-- <?php echo Yii::t('helpdesk','All'); ?> --</option>
                <?php foreach($arrLogActions as $R): ?>
                <option value="<?php echo $R; ?>" <?php if($arrFilters['log_action'] == $R): ?>selected<?php endif; ?>><?php echo Yii::t('helpdesk',$R); ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <div class="form-group">
            <label for="dfrom" class="col-md-1"><?php echo Yii::t('helpdesk','Date'); ?>:</label>	
           	<input type="text" name="dfrom" id="dfrom" value="<?php echo $arrFilters['log_time']['from']; ?>" class="txtdate" readonly /> - <input type="text" name="dto" id="dto" value="<?php echo $arrFilters['log_time']['to']; ?>" class="txtdate" readonly /> 
        </div>
        <div class="form-group col-md-2">
            <input type="submit" value="<?php echo Yii::t('helpdesk','Search'); ?>">
            <input type="button" value="<?php echo Yii::t('helpdesk','Reset'); ?>" onClick="freset();">
		</div>
    </fieldset>
</form>

<table class="list-tickets table table-striped table-bordered">
    <tbody>
    	<tr>
            <th><?php echo Yii::t('helpdesk','Event'); ?></th>
            <th width="145"><?php echo Yii::t('helpdesk','Time'); ?></th>
    	</tr>
        <?php if(!empty($arrLogs)): ?>
        <?php foreach($arrLogs as $R): ?>        
        <tr>
            <td><?php echo $R['log_message']; ?></td>
            <td class="date"><?php echo date("d/m/y H:i:s", strtotime($R['log_time'])); ?></td>     
        </tr>
        <?php endforeach; ?>  
        <?php else: ?>
        <tr>
        	<td colspan="5"><?php echo Yii::t('helpdesk','No data found'); ?></td>
        </tr>
        <?php endif; ?>     
	</tbody>
</table>
<?php $this->widget('Pagination', array(
	'pages' => $objPages,
)) ?>
<script type="text/javascript">
	$(document).ready(function(){
		$("#dfrom").datepicker({
			dateFormat:'dd-mm-yy',
			maxDate: '0',
			changeMonth: true,
			changeYear: true,
			onClose: function( selectedDate ) {
				if(selectedDate != ''){
					$("#dto").datepicker( "option", "minDate", selectedDate );
				}
			}
		});
		$("#dto").datepicker({
			dateFormat:'dd-mm-yy',
			maxDate: '0',
			changeMonth: true,
			changeYear: true,
			onClose: function( selectedDate ) {
				if(selectedDate != ''){
					$("#dfrom").datepicker( "option", "maxDate", selectedDate );
				}
			}
		});
		$('#frmFilter legend').click(function(){
			 $( "#frmFilter .form-group" ).toggle( "slow" );
			 $( "#frmFilter #filterIcon" ).toggleClass( "fa-plus-square-o", "fa-minus-square-o" );
		});	
	});
	function freset(){
		$('#frmFilter select').val('');
		$('#frmFilter input[type=text]').val('');
		$('#frmFilter').submit();
	}
</script>